﻿/// <reference path="../Controls/BaseControl.js" />
/// <reference path="../Turbo/FieldBinding.js" />
/// <reference path="../General/Events/EventSender.js" />
/// <reference path="../Turbo/ServerEventSender.js" />


var ____a;

var $SimpleControl = TA.Turbo.Controls.SimpleControl = function SimpleControl(clientId)
{
	if (Function.IsInherit(arguments)) return;

	this.BaseControl(clientId);
	this.ServerEventSender();
}
$SimpleControl.Inherit($BaseControl);
$SimpleControl.Inherit(TA.Turbo.Common.ServerEventSender);

$SimpleControl.prototype._eventDefinitions = new Object();
$SimpleControl.DefineEvent = function DefineEvent(eventDef)
{
	this.prototype._eventDefinitions[eventDef._name] = eventDef;
}

if (____a)
{
	$SimpleControl.prototype = new $BaseControl();
	$SimpleControl.prototype.BaseControl = new $BaseControl();
}

$PropertyDefinition.Define($SimpleControl, "Data", "D", new $FieldBinding(), {
	Serializable: $FieldBinding
});

$PropertyDefinition.Define($SimpleControl, "Text", "Tx", "", {
	GetInitValue: function GetInitValue(obj)
	{
		return obj._TextGetInitValue();
	},
	OnChanged: function _OnTextChanged()
	{
		this.RaiseEvent("TextChanged");

		this.get_Control().innerHTML = this._properties.Text;
	}
});

$SimpleControl.DefineEvent(new $ServerEvent("ValueChanged"));

$SimpleControl.prototype._TextGetInitValue = function _TextGetInitValue()
{
	return this.get_Control().innerHTML;
}

// INSTANCE
$SimpleControl.prototype.get_Value = function get_Value()
{
	return this.get_Control().innerHTML;
}
$SimpleControl.prototype.set_Value = function set_Value(v)
{
	this.get_Control().innerHTML = v;
	this._OnValueSet();
}
$SimpleControl.prototype.get_SerializedValue = function get_SerializedValue()
{
	return this.get_Value();
}
$SimpleControl.prototype.set_SerializedValue = function set_SerializedValue(value)
{
	this.set_Value(value);
}
$SimpleControl.prototype.Load = function Load()
{
	this.BaseControl.Load.call(this);
}




// INTERNAL
$SimpleControl.prototype._OnValueSet = function _OnValueSet()
{
	this.RaiseEvent("ValueSet");
}
$SimpleControl.prototype._OnValueChanged = function _OnValueChanged()
{
	this.RaiseEvent("ValueChanged");
}

$SimpleControl.prototype.Load = function Load()
{
	this.BaseControl.Load.call(this);
}






$SimpleControl.RaiseEvent = function RaiseEvent(e, action)
{
	var sender = Events.GetSender(e);

	if (sender.disabled || sender.getAttribute("disabled") != null)
	{
		return false;
	}

	try
	{
		var result = action.call(sender, e);
		if (result != null)
		{
			return result;
		}
	}
	catch (ex)
	{
	}

	return false;
}
$SimpleControl.RaiseServerEvent = function RaiseServerEvent(e, handler, psId, arg, eventName)
{
	return $SimpleControl.RaiseEvent(e, function(e)
	{
		if (handler != null)
		{
			var res = handler.call(this);
			if (res === false)
				return false;
		}
		
		$DoPostBack(this, eventName, arg, psId);
	});
}
$SimpleControl.RaiseClick = function RaiseClick(e, handler, psId, arg)
{
	return $SimpleControl.RaiseServerEvent(e, handler, psId, arg, "Click");
}
$SimpleControl.RaiseValueChanged = function RaiseValueChanged(e, handler, psId, arg)
{
	return $SimpleControl.RaiseServerEvent(e, handler, psId, arg, "ValueChanged");
}
$SimpleControl.RaiseClientEvent = function RaiseClientEvent(e, handler)
{
	return $SimpleControl.RaiseEvent(e, handler);
}













Element.prototype.get_Object = function get_Object()
{
	if (this.id == ""
		||
		this.id.EndsWith(TA.Turbo.Common.StateFieldClientIdPostfix)
		)
		return null;
	var obj;
	switch (this.tagName)
	{
		case "INPUT":
			switch (this.type)
			{
				case "password":
				case "text": obj = new $TextBox(this.id); break;
				case "checkbox":
				case "radio": obj = new $ToggleControl(this.id); break;
				case "hidden": obj = new $InputControl(this.id); break;
				case "submit":
				case "button": obj = new $Button(this.id); break;
				case "image": obj = new $ImageButton(this.id); break;
			}
			break;
		case "SELECT":
			obj = new $SelectControl(this.id); break;
		case "TEXTAREA":
			obj = new $TextBox(this.id); break;
		case "IMG":
			obj = new $ImageControl(this.id); break;
		case "A":
			obj = new $LinkControl(this.id); break;
		case "SPAN":
			switch (this.getAttribute("type"))
			{
				case "radiogroup":
					obj = new $RadioGroup(this.id); break;
			}
	}
	if (obj == null)
		obj = new $SimpleControl(this.id);
	obj.Init();
	obj.Load();
	return obj;
}



